import { getStorage } from '../../utils/storage'

export default (state = {
  adminname: getStorage('adminname') || '',
  role: getStorage('role') || 0,
  token: getStorage('token') || '',
  loginState: getStorage('loginState') === 'true' || false
}, { type, payload}) => {
  switch (type) {
    case 'CHANGE_ADMIN_NAME':
      return {...state, adminname: payload }
    case 'CHANGE_ROLE':
      return {...state, role: payload }
    case 'CHANGE_TOKEN':
      return {...state, token: payload }
    case 'CHANGE_LOGIN_STATE':
      return {...state, loginState: payload }
    default:
      return state
  }
}